<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <title>厳選SHOP - トクバイ</title>
    <!-- Path to Framework7 Library CSS-->
    <link rel="stylesheet" href="{{ asset('style/plugins/bootstrap/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('style/plugins/framework7/css/framework7.ios.css') }}">
    <link rel="stylesheet" href="{{ asset('style/plugins/framework7/css/framework7.ios.colors.css') }}">
    <link rel="stylesheet" href="{{ asset('style/plugins/fontawesome/css/font-awesome.min.css') }}">
    <!-- Path to your custom app styles-->
    <link rel="stylesheet" href="{{ asset('style/wx/css/my-app.css') }}">
</head>
<body class="theme-orange">
<!-- Panels Overlay -->
<div class="panel-overlay"></div>

<!-- Left Panel with Reveal effect -->
<div class="panel panel-left panel-reveal">
    <div class="content-block">
        <p>选择学校</p>
        <!-- Click on link with "close-panel" class will close panel -->
        @foreach($store as $v)
            <p><a href="{{ action('Wx\IndexController@getIndex', ['storeID' => $v->id]) }}" data-storeid="{{ $v->id }}" class="close-panel">{{ $v->name }}</a></p>
        @endforeach
    </div>
</div>
<!-- Views -->
<div class="views">
    <div class="view view-main">

        <!-- Top Navbar-->
        <div class="navbar">
            <div class="navbar-inner">
                <div class="left">
                    <a href="#" class="link open-panel">
                        <i class="fa fa-map-marker"></i>
                        <span id="storeName">{{ $store[$storeID]->name }}</span>
                    </a>
                </div>
            </div>
        </div>
        <!-- /End of Top Navbar-->

        <!-- Now we need additional "navbar-through" and "toolbar-through" classes on Pages -->
        <div class="pages navbar-through toolbar-through">
            <div data-page="index" class="page">
                <script id="indexTemplate" type="text/template7">
                    @{{#each people}}
                    <li>@{{firstName}} @{{lastName}}</li>
                    @{{/each}}
                </script>
                <div class="page-content infinite-scroll">
                    <div class="swiper-container swiper-1">
                        <div class="swiper-pagination"></div>
                        <div class="swiper-wrapper">
                            <div class="swiper-slide"><img src="{{ asset('style/wx/img/20170826.jpg') }}" width="100%"></div>
                        </div>
                    </div>
                    <div class="content-block bg-white" style="margin-top: 0">
                        <div class="row type-box">
                            <div class="col-25">
                                <a href="?typeID=1">
                                    <div class="adaptive-circle bg-green">
                                        <div class="layout middle">
                                            <span>欢</span>
                                        </div>
                                    </div>
                                </a>
                                <p>水果</p>
                            </div>
                            <div class="col-25">
                                <a href="?typeID=2">
                                    <div class="adaptive-circle bg-yellow">
                                        <div class="layout middle">
                                            <span>迎</span>
                                        </div>
                                    </div>
                                </a>
                                <p>零食</p>
                            </div>
                            <div class="col-25">
                                <a href="?typeID=3">
                                    <div class="adaptive-circle bg-blue">
                                        <div class="layout middle">
                                            <span>光</span>
                                        </div>
                                    </div>
                                </a>
                                <p>干果</p>
                            </div>
                            <div class="col-25">
                                <a href="?typeID=4">
                                    <div class="adaptive-circle bg-red">
                                        <div class="layout middle">
                                            <span>临</span>
                                        </div>
                                    </div>
                                </a>
                                <p>绝味</p>
                            </div>
                        </div>
                    </div>

                    <!--分类-->
                    <div class="content-block bg-white lh-3">
                        <div class="row">
                            <div class="col-50 text-center">
                                <!-- Single button -->
                                <div class="dropdown">
                                    <a type="button" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        @if(isset($_GET['typeID']) && isset($classify[$_GET['typeID']])){{ $classify[$_GET['typeID']]->name }}@else 全部分类 @endif <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                        @if(isset($_GET['typeID']) && isset($classify[$_GET['typeID']]))
                                        <li><a href="?typeID=">全部分类</a></li>
                                        @endif
                                        @foreach($classify as $v)
                                                @if(!isset($_GET['typeID']) || $v->id != $_GET['typeID'])
                                                    <li><a href="?typeID={{ $v->id }}">{{ $v->name }}</a></li>
                                                @endif
                                        @endforeach
                                    </ul>
                                </div>
                            </div>
                            <div class="col-50 text-center">
                                <!-- Single button -->
                                <div class="dropdown">
                                    <a type="button" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        综合排序 <span class="caret"></span>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!--列表-->

                    <div id="indexData" class="list-block media-list" data-typeID="{{ $typeID }}" data-storeID="{{ $storeID }}" data-token="{{ csrf_token() }}" data-url="{{ action('Wx\IndexController@postIndex') }}">
                        <ul>
                            @foreach($goods as $v)
                                <li id="goods-{{ $v->id }}">
                                    <a href="#" class="item-link item-content">
                                        <div class="item-media"><img data-src="{{ action('ImgController@getPicture', ['sourceName' => $v->thumb, 'size' => '80x80']) }}" width="80" class="lazy lazy-fadein"></div>
                                        <div class="item-inner">
                                            <div class="item-title-row closeLink">
                                                <div class="item-title">{{ $v->title }}</div>
                                                <div class="item-after">{{ $v->realAmount }} 円</div>
                                            </div>
                                            <div class="item-text">{{ $v->abstract }}</div>
                                        </div>
                                    </a>
                                    {{--<div class="shop-add">--}}
                                        {{--<i class="fa fa-cart-arrow-down hidden"></i>--}}
                                        {{--<span data-id="{{ $v->id }}" data-amount="{{ $v->realAmount }}"></span>--}}
                                        {{--<i class="fa fa-cart-plus"></i>--}}
                                    {{--</div>--}}
                                    <div class="form-group shop-add">
                                        <div class="col-xs-6"></div>
                                        <div class="col-xs-6">
                                            <p class="buttons-row">
                                                <a href="#" class="button down hidden"><i class="fa fa-cart-arrow-down fa-2x"></i></a>
                                                <span class="button" data-id="{{ $v->id }}" data-amount="{{ $v->realAmount }}"></span>
                                                <a href="#" class="button plus"><i class="fa fa-cart-plus fa-2x"></i></a>
                                            </p>
                                        </div>
                                    </div>
                                </li>
                            @endforeach
                        </ul>
                    </div>
                    <!-- Preloader -->
                    <div class="infinite-scroll-preloader">
                        <div class="preloader"></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="cart tabbar hidden">
            <div class="toolbar-inner">
                总计：<sapn id="sumAmount"></sapn>円
                <a href="#" data-popup=".popup-pay" id="popup-pay"  class="button button-fill button-red open-popup">购买</a>
            </div>
        </div>
        <!-- Bottom Toolbar-->
        <div class="toolbar tabbar">
            <div class="toolbar-inner">
                <a href="{{ action('Wx\IndexController@getIndex') }}" id="index" class="link active">
                    <i class="fa fa-home"></i>
                </a>
                <a href="{{ action('Wx\CartController@getIndex') }}" id="cart" class="link">
                    <i class="fa fa-shopping-cart"></i>
                </a>
                <a href="{{ action('Wx\UserController@getIndex') }}" id="user" class="link">
                    <i class="fa fa-user"></i>
                </a>
            </div>
        </div>
        <!-- /End of Bottom Toolbar-->

    </div>
</div>
<!-- Path to Framework7 Library JS-->
<script type="text/javascript" src="{{ asset('style/plugins/jquery/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('style/plugins/framework7/js/framework7.js') }}"></script>
<script type="text/javascript" src="{{ asset('style/plugins/bootstrap/js/bootstrap.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('style/plugins/jquery-cookie/jquery.cookie.js') }}"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<!-- Path to your app js-->
<script type="text/javascript" src="{{ asset('style/wx/js/my-app.js') }}"></script>
<script>
    var tipSearch = function(){
        myApp.alert('功能开发中');
        return false;
    }
    $$(document).on('ajaxStart', function (e) {
        myApp.showIndicator();
    });
    $$(document).on('ajaxComplete', function (e) {
        myApp.hideIndicator();
    });
    var WXPayment = function() {
        var address = $$('#picker-address').val();
        var shopTime = $$('#shop-time').val();
        $$.ajax({
            url: '{{ action('Wx\CartController@postPay') }}',
            method: 'POST',
            dataType: 'json',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            data: {
                address: address,
                shopTime: shopTime
            },
            success: function (data) {
                if (data.code == 200)
                {
                    WeixinJSBridge.invoke(
                        'getBrandWCPayRequest', data.config, function(res) {
                            switch(res.err_msg) {
                                case 'get_brand_wcpay_request:cancel':
                                    myApp.alert('支付取消！');
                                    break;
                                case 'get_brand_wcpay_request:fail':
                                    myApp.alert('支付失败！（'+res.err_desc+'）');
                                    break;
                                case 'get_brand_wcpay_request:ok':
                                    myApp.alert('支付成功！');
                                    $.cookie('cart', null, { path: '/', expires: 0 });
                                    myApp.closeModal('.popup-pay');
                                    mainView.router.loadPage('{{ action('Wx\IndexController@getIndex') }}');
                                    break;
                                default:
                                    myApp.alert('异常错误！');
                                    myApp.closeModal('.popup-pay');
                                    mainView.router.loadPage('{{ action('Wx\IndexController@getIndex') }}');
                                    break;
                            }
                        }
                    );
                } else if (data.code == 400) {
                    myApp.alert(data.msg);
                }
            }
        });
    }
    var ajaxGetAddress = function() {
        $$.ajax({
            url: '{{ action('Wx\UserController@getAddressList') }}',
            method: 'GET',
            dataType: 'json',
            success: function (data) {
                $address = data;
            }
        });
    }
    $$('#popup-pay').on('click', function () {
        $$.ajax({
            url: '{{ action('Wx\CartController@getGetCart') }}',
            method: 'GET',
            dataType: 'json',
            success: function (data) {
                $$('#payList').html(data.data);
            }
        });
    });
    var $address;
    ajaxGetAddress();
    $(function () {
        $.refreshJs('index');
        $.getGoodsList('index', $$('#indexData').data('typeID'));
        $.mcookie('index');
    });
</script>
</body>
</html>